package com.film.web.controller.item;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.film.common.annotation.Log;
import com.film.common.core.controller.BaseController;
import com.film.common.core.domain.AjaxResult;
import com.film.common.enums.BusinessType;
import com.film.item.domain.Item;
import com.film.item.service.IItemService;
import com.film.common.utils.poi.ExcelUtil;
import com.film.common.core.page.TableDataInfo;

/**
 * 创建项目Controller
 * 
 * *@author fy
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/item/item")
public class ItemController extends BaseController
{
    @Autowired
    private IItemService itemService;

    /**
     * 查询创建项目列表
     */
    @PreAuthorize("@ss.hasPermi('item:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(Item item)
    {
        startPage();
        List<Item> list = itemService.selectItemList(item);
        return getDataTable(list);
    }

    /**
     * 导出创建项目列表
     */
    @PreAuthorize("@ss.hasPermi('item:item:export')")
    @Log(title = "创建项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Item item)
    {
        List<Item> list = itemService.selectItemList(item);
        ExcelUtil<Item> util = new ExcelUtil<Item>(Item.class);
        util.exportExcel(response, list, "创建项目数据");
    }

    /**
     * 获取创建项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('item:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(itemService.selectItemById(id));
    }

    /**
     * 新增创建项目
     */
    @PreAuthorize("@ss.hasPermi('item:item:add')")
    @Log(title = "创建项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Item item)
    {
        return toAjax(itemService.insertItem(item));
    }

    /**
     * 修改创建项目
     */
    @PreAuthorize("@ss.hasPermi('item:item:edit')")
    @Log(title = "创建项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Item item)
    {
        return toAjax(itemService.updateItem(item));
    }

    /**
     * 删除创建项目
     */
    @PreAuthorize("@ss.hasPermi('item:item:remove')")
    @Log(title = "创建项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)

    {
        return toAjax(itemService.deleteItemByIds(ids));
    }
    /**
     * 统计不同状态的项目数量
     */
    @PreAuthorize("@ss.hasPermi('item:item:list')")
    @GetMapping("/status/count")
    public AjaxResult countItemsByStatus()
    {
        List<Map<String, Object>> statusCounts = itemService.countItemsByStatus();
        return AjaxResult.success(statusCounts);
    }
    /**
     * 查询各类型的剧目预算的变化趋势
     */
    @PreAuthorize("@ss.hasPermi('item:item:list')")
    @GetMapping("/budget/trend")
    public AjaxResult countItemsBudgetByYearAndType()
    {
        List<Map<String, Object>> budgetTrends = itemService.countItemsBudgetByYearAndType();
        return AjaxResult.success(budgetTrends);
    }

    /**
     * 查询各类型的剧目数量
     */
    @PreAuthorize("@ss.hasPermi('item:item:list')")
    @GetMapping("/type/count")
    public AjaxResult countItemsByType()
    {
        List<Map<String, Object>> typeCounts = itemService.countItemsByType();
        return AjaxResult.success(typeCounts);
    }

}
